package librarymanager

import grails.test.mixin.TestFor
import spock.lang.Specification

/**
 * See the API for {@link grails.test.mixin.domain.DomainClassUnitTestMixin} for usage instructions
 */
@TestFor(Author)
class AuthorSpec extends Specification {

    def setup() {
    }

    def cleanup() {
    }

    void "Test the name's size constraint"() {
        when: "The name's size is less than 3 characters"
            def a = new Author(name: "Te")
        
        then: "The test should fail"
            !a.validate()
        
        when: "The name's size is over than 50 characters"
            a = new Author(name: "This is a test name which size is over than 50 characters")
        
        then: "The test should fail"
            !a.validate()
        
        when: "The name's size is more than 3 and less than 50"
            a = new Author(name: "Author Test 2")
        
        then: "The test should pass"
            a.validate()
    }
    
    void "Test the name nullable constraint"() {
        when: "The name is null"
            def a = new Author()
            
        then: "The test should fail"
            !a.validate()
    }
    
    void "Test the name blank constraint"() {
        when: "The name is blank"
            def a = new Author(name: "")
            
        then: "The test should fail"
            !a.validate()
    }
}
